define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');

var history = require('component-history');
	
require('component-page');

	var realName = "", userAgentId = "";

	exports.init=function(m){
		history.addHis(this,arguments);
	    window.$ddf_operator = m;

		var htmlStr = "";

		htmlStr += '<div id="content-header">';
		htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'
				+ ddf.index.index_js
				+ '") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">操作员查询</a></div>';
//		htmlStr += '<h1>操作员查询</h1>';
		htmlStr += '</div>    ';

		htmlStr += '<div class="container-fluid">';
//		htmlStr += '<hr/>';

		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title">';
		htmlStr += '<span class="icon"><i class="icon-search"></i></span>';
		htmlStr += '<h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button>';
		htmlStr += '</div>        ';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6">';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">操作员代码：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span8 m-wrap" type="text" id="userAgentId"/>';
		htmlStr += '</div>                          ';
		htmlStr += '</div>';
		htmlStr += '</div>';

		htmlStr += '</div> ';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6">';
		htmlStr += '<div class="control-group">';
		htmlStr += '<label class="control-label">真实姓名：</label>';
		htmlStr += '<div class="controls">';
		htmlStr += '<input class="span8 m-wrap" type="text" id="realName"/>';
		htmlStr += '</div>     ';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>   ';
		htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_operator.searchOperator()" >搜索</button>';
		htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_operator.resetSearchParams()">重置</button>';
		htmlStr += '</div>         ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>用户列表</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
		htmlStr += '<table class="table table-bordered data-table">';
		htmlStr += '<thead>';
		htmlStr += '<tr>';
		htmlStr += '<th>序号</th>';
		htmlStr += '<th>操作员代码</th>';
		htmlStr += '<th>登录用户名</th>';
		htmlStr += '<th>真实姓名</th>';
//		htmlStr += '<th>操作</th>';
		htmlStr += '</tr>';
		htmlStr += '</thead>';
		htmlStr += '<tbody id="operatorList">';

		htmlStr += '</tbody>';
		htmlStr += '</table>';
		htmlStr += '<div id="footPageDiv0">';

		htmlStr += '</div>';
		htmlStr += '</div>';

		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div>';

		showDiv("content0");

		$("#content0").html(htmlStr);

		getOperatorList(1,pageSize, userAgentId, realName);

	}

	/**
	 * 获取商家列表
	 * 
	 * @param pageNumber
	 * @param shopname
	 * @param mobile
	 * @param agentId
	 */
	function getOperatorList(pageNumber,pageSize, userAgentId, realName) {

		var params = {
			"page.pageNumber" : pageNumber,
			"page.pageSize" : pageSize,
			"userAgentId" : userAgentId,
			"realName" : realName
		};

		base.showLoading();

		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.operator.queryAllByAgentId,params));
			
			getOperatorListCallBack(data);
			
		}))().start();
	}

	/**
	 * 获取商家列表_回调函数
	 */
	function getOperatorListCallBack(data) {

		if (data["code"] == 1) {

			var htmlStr = "";

			for (var i = 0; i < data["resultList"].length; i++) {

				htmlStr += '<tr>';
				htmlStr += '<td>' + getSequence(data["pageNumber"], i + 1)
						+ '</td>';
				htmlStr += '<td>' + data["resultList"][i]["userAgentId"]
						+ '</td>';
				htmlStr += '<td>' + data["resultList"][i]["userName"] + '</td>';
				htmlStr += '<td>' + data["resultList"][i]["realName"] + '</td>';
//				htmlStr += '<td><a href=javascript:$ddf_operator.updateMemo("'+data["resultList"][i]["userAgentId"]+'")>修改备注名</a></td>';
				htmlStr += '</tr> ';

			}

			$("#operatorList").html(htmlStr);

			 $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
				 
				 changePageCallback:function(pageSize,page){ 
					 getOperatorList(page,pageSize, userAgentId, realName);
				 },
				 changePageSizeCallBack:function(pageSize){
					 getOperatorList(1,pageSize, userAgentId, realName);
				 } 
		     }); 

		} else {

			base.tips_error(data["message"]);
		}

		base.cancelLoading();
	}

	/**
	 * 重置参数
	 */
	function resetSearchParams() {

		realName = "";
		userAgentId = "";
		$("#realName").val("");
		$("#userAgentId").val("");

	}
	/**
	 * 搜索商家
	 */
	function searchOperator() {

		userAgentId = $("#userAgentId").val();

		realName = $("#realName").val();

		$ddf_operator.getOperatorList(1,pageSize, userAgentId, realName);
		// $ddf_shop.getShopList(1,shopname,mobile,shopId);

	}
	
	var uAId = '';
	//修改备注名
	 exports.updateMemo=function(id){
		 uAId = id;
	 	var title="修改备注名";
	 	var btnleft="确定";
	 	var btnright="取消";
	 	var changepwd=
	 		'<div id="'+id+'" class="modal">' +
	 			 '<div class="modal-header">' +
	 				 '<button class="close over" type="button">×</button>' +
	 				 '<h3>'+title+'</h3>' +
	 			 '</div>' +
	 			 '<div class="modal-body form-horizontal"><div class="row-fluid">'+
	 				 	'<div class="control-group" id="control-group-edit-pwd"><label class="control-label">备注名：</label><div class="controls"><input type="text" id="memo" class="span8 m-wrap"  /></div></div>'+
	 			 '</div></div>'+
	 			 '<div class="modal-footer"> <button type="button" class="btn btn-primary" onclick=$ddf_operator.editMemo("'+id+'")>'+btnleft+'</button> <button class="btn over" type="button">'+btnright+'</button> </div>'+
	 		'</div>';
	 	$(changepwd).appendTo("body");
	 	$("<div class='modal-backdrop in'></div>").appendTo("body");
	 	$("#"+id).find(".over").click(function(){
	 		$("#"+id).remove();	
	 		$("body .modal-backdrop").remove();	
	 	});

	 };
	 
	 /**
	  * 确认修改
	  */
	 exports.editMemo=function(userId){
	 	
	 	var memo=$("#memo").val();
	 	
	 	
	 	var params={
	 			
	 			"userAgentId":uAId,
	 			"memo":memo
	 			
	 	        };
	 	

	 	base.showLoading();
	 	
	 	
	 	eval(Wind.compile("async",function(){
	 		
	 		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.operator.editMemo,params));
	 		
	 		editMemoCallBack(data,uAId);
	 		
	 	}))().start();
	 	
	 };

	 /**
	  * 确认修改_回调函数
	  */
	 function editMemoCallBack(data,_uAId){
		 
		 base.cancelLoading();
		 $("#"+_uAId).remove();	
		 $("body .modal-backdrop").remove();	
		 
	 	if(data["code"]==1){
	 		
	 		base.tips("修改成功");
	 		getOperatorList(1,pageSize, userAgentId, realName);
	 	}else{
	 		 base.tips_error(data["message"]);
	 	}
	 	
	 	
	 }

	/**
	 * 显示DIV
	 */
	function showDiv(block){
		
		$("#content > div").hide();
		
		if($("#"+block).length<=0){
			
			$("#content").append('<div id="'+block+'"></div>'); 
			
		}else{
			
			$("#"+block).show();
		}
		
		if(block=="content0"){
			shopTypeId="";
		}
		

		
	}

	/**
	 * 对外提供访问的方法
	 */

	exports.getOperatorList = getOperatorList; // 获取商家列表
	exports.resetSearchParams = resetSearchParams; // 重置参数
	exports.searchOperator = searchOperator; // 搜索
	exports.showDiv = showDiv; 
});
